fix: bound inline SSE event size in Streamable HTTP client#841
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a defensive size bound to inline SSE parsing for Streamable HTTP POST responses so that a non-terminating or oversized SSE event cannot grow the client buffer without limit.
Changes:
- Introduces
maxInlineSseEventSize(default 16 MiB) and enforces it while parsing inline SSE (data:accumulation + per-line bounds). - Adds unit tests covering oversized inline SSE events, exact-bound acceptance, and invalid configuration.
- Updates the public API dump to reflect the new constructor signature.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpClientTransport.kt | Adds max-size configuration and enforces bounds while parsing inline SSE from POST responses. |
| kotlin-sdk-client/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/streamable/http/StreamableHttpClientTransportTest.kt | Adds unit tests for oversized/exact-size inline SSE events and invalid max size. |
| kotlin-sdk-client/api/kotlin-sdk-client.api | Updates API dump for the changed StreamableHttpClientTransport constructor signature. |
Comments suppressed due to low confidence (1)
kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpClientTransport.kt:111
- The deprecated constructor's
ReplaceWithsuggestion is now invalid because the primary constructor gained amaxInlineSseEventSize: Intparameter. As written, the replacement call passesrequestBuilderpositionally as the 4th argument, which will now be treated asmaxInlineSseEventSizeand fail to compile. Use a named argument forrequestBuilder(and/or supplymaxInlineSseEventSize).
replaceWith = ReplaceWith(
"StreamableHttpClientTransport(client, url, " +
"ReconnectionOptions(initialReconnectionDelay = reconnectionTime ?: 1.seconds), requestBuilder)",
"kotlin.time.Duration.Companion.seconds",
"io.modelcontextprotocol.kotlin.sdk.client.ReconnectionOptions",
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+486
to
+490
| val line = try { | ||
| channel.readUTF8Line(maxInlineSseEventSize) | ||
| } catch (_: TooLongLineException) { | ||
| throw TooLongFrameException(maxInlineSseEventSize.toLong() + 1, maxInlineSseEventSize) | ||
| } |
Comment on lines
+88
to
92
| * @param maxInlineSseEventSize maximum size, in characters, of a single inline SSE event parsed from a | ||
| * POST response; a server that exceeds it (including by never terminating an event) fails the send | ||
| * with [io.modelcontextprotocol.kotlin.sdk.shared.TooLongFrameException]. Defaults to 16 MiB. | ||
| * @param requestBuilder builder applied to every outgoing HTTP request, e.g. for adding auth headers | ||
| */ |
Comment on lines
+104
to
+105
| public fun <init> (Lio/ktor/client/HttpClient;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/client/ReconnectionOptions;ILkotlin/jvm/functions/Function1;)V | ||
| public synthetic fun <init> (Lio/ktor/client/HttpClient;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/client/ReconnectionOptions;ILkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V |
e5l
approved these changes
Jun 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bound the size of a single inline SSE event parsed from a POST response in
StreamableHttpClientTransport, so a non-conforming or unbounded server response cannot grow the client's buffer without limit.How Has This Been Tested?
New unit tests
Breaking Changes
none
Types of changes
Checklist